home *** CD-ROM | disk | FTP | other *** search
- Path: web.cae.ca!usenet
- From: fraserh@cae.ca (Fraser Hutchinson)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Simple question about constructors
- Date: 6 Mar 1996 18:11:41 GMT
- Organization: CAE Electronics Ltd.
- Message-ID: <4hkkgt$bpi@web.cae.ca>
- References: <4ha7d2$quc@cloner4.netcom.com> <4hbadp$t0p@cloner4.netcom.com>
- NNTP-Posting-Host: pch63.cae.ca
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <4hbadp$t0p@cloner4.netcom.com>, stefmit@ix.netcom.com says...
- >
- >It seems that the "copy constructor" day is one of my worst in the C++
- >learning process. Now I ran into another problem:
-
- [description of class purpose deleted]
-
- I have a linked list based on a template <class My_type>, which has a node
- >class with (obviously) a pointer (let's call it *next) and an element field of
- >the type My_type (called data). Then, I have a list class using the node
- >above, with its own pointer *head (I am trying to build a sort of stack). I
- >was able to build the stack (this was pretty easy), but then I tried to define
- >a copy constructor in the list, using something similar to:
- >template <class My_type>
- >List<My_type> :: List(const List &newList)
- >{ head -> data = newList.head -> data;
- ^^^^^^^^^^^^
- > head -> next = newList.head -> next; }
- ^^^^^^^^^^^^
-
- OK, silly question, but has memory been allocated for this::head? That this
- is a constructor implies to me that there hasn't, which means that you are
- writing to a random memory location.
-
- Fraser
-
-
-